﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace Spore.Validator
{
    /// <summary>
    /// IP地址验证器
    /// </summary>
    public  class ValidatorIPAddress:ValidatorBase
    {
        private static ValidatorIPAddress _default;

        /// <summary>
        /// 默认的验证器
        /// </summary>
        public static ValidatorIPAddress Default
        {
            get
            {
                if (_default == null)
                    _default = new ValidatorIPAddress();
                return _default;
            }
        }
       
        public ValidatorIPAddress()
        {
            this.ErrorMessage = "您的输入不符合IP地址格式！";
        }

        /// <summary>
        ///验证内容是否大于指定值
        /// </summary>
        /// <param name="controlToValidate">要验证的控件</param>
        /// <returns></returns>
        public override bool IsValid(Control controlToValidate)
        {
            string content = controlToValidate.Text.Trim();
            System.Net.IPAddress tmp;
            if (System.Net.IPAddress.TryParse(content, out tmp))
                return true;
           return false;
        }
    }
}
